﻿using Microsoft.Extensions.Configuration;
using Quartz;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Domain.PlcConnectPoolDomain;

namespace Zocono.WCS.HangfireHost.QuartzCore
{
    public class HeartJob : IJob
    {
        private readonly IPlcConnectionPoolService _plcConnetionPoolService;

        public HeartJob(IPlcConnectionPoolService plcConnetionPoolService)
        {
            _plcConnetionPoolService = plcConnetionPoolService;
        }
        /// <inheritdoc/>

        public async Task Execute(IJobExecutionContext context)
        {
            await Console.Out.WriteLineAsync($"{DateTime.Now}:test1");
            //MyPrograme myPrograme = _configuration.GetSection("MyPrograme").Get<MyPrograme>();
            //将所有程序放到一个集合中，方便plc连接
            List<string> list = new();
            //if (myPrograme != null)
            //{
            //    foreach (var Programe in myPrograme.ProgrameName.Pro_1001)
            //    {
            //        list.Add(Programe);
            //    }
            //    foreach (var Programe in myPrograme.ProgrameName.Pro_2001)
            //    {
            //        list.Add(Programe);
            //    }
            //    foreach (var Programe in myPrograme.ProgrameName.Pro_3001)
            //    {
            //        list.Add(Programe);
            //    }
            //    foreach (var Programe in myPrograme.ProgrameName.Pro_4001)
            //    {
            //        list.Add(Programe);
            //    }
            //    foreach (var Programe in myPrograme.ProgrameName.Pro_5001)
            //    {
            //        list.Add(Programe);
            //    }
            //}
            try
            {
                await _plcConnetionPoolService.S7Heartbeat(list);
                await Console.Out.WriteLineAsync($"{DateTime.Now}:test4");
            }
            catch (Exception ex)
            {
                await Console.Out.WriteLineAsync($"{DateTime.Now}:test2");
            }
            await Console.Out.WriteLineAsync($"{DateTime.Now}:test3");
        }
    }
}
